home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / COUPON.TST / PLANCUPN.C < prev    next >
C/C++ Source or Header  |  1995-12-01  |  2KB  |  86 lines

  1. /* ============ */
  2. /* plancupn.c    */
  3. /* ============ */
  4. #include <defcodes.h>
  5. #include <miscdefs.h>
  6. #include <cupnprob.c>
  7.  
  8. /* ==================================================================== */
  9. /* PlanCupn - Prints Sample Sizes Required for Coupon Collector's Test    */
  10. /* ==================================================================== */
  11. void
  12. main()
  13. {
  14.     AbortGracefully();            /* Causes ^C to Behave */
  15.  
  16.     while (main)
  17.     {
  18.     int    k;
  19.     char    *LeftLbl;
  20.     int    CellExpect, MaxLength, SetSize;
  21.     double    CouponProbs[100], TotalProb;
  22.  
  23.     GetInt("Enter Number of Unique Integers in Data Set:\t",
  24.         &SetSize);
  25. #define    DFLT_DATA_SET    10
  26.  
  27.     if (SetSize > 0)
  28.     {
  29.         printf("Size of Data Set = %d\n", SetSize);
  30.     }
  31.     else
  32.     {
  33.         SetSize = DFLT_DATA_SET;
  34.         printf("Data Set is set to %d Integers by default\n",
  35.         SetSize);
  36.     }
  37.  
  38.     for (;;)
  39.     {
  40.         GetInt("Enter Maximum Length of a Segment:\t\t",
  41.         &MaxLength);
  42.  
  43.         if (MaxLength > SetSize)
  44.         {
  45.         break;
  46.         }
  47.         printf("Number Must Exceed %d (Size of Data Set)\n",
  48.         SetSize);
  49.     }
  50.  
  51.     GetInt("Enter Minimum Expectation For Each Segment:\t",
  52.         &CellExpect);
  53.  
  54. #define    DFLT_CELL_COUNT    5
  55.  
  56.     if (CellExpect > 0)
  57.     {
  58.         printf("Minimum Cell Expectation = %d\n", CellExpect);
  59.     }
  60.     else
  61.     {
  62.         CellExpect = DFLT_CELL_COUNT;
  63.         printf("Minimum Cell Expectation is set to %d by default\n",
  64.         CellExpect);
  65.     }
  66.     CalcCouponProbs(SetSize, MaxLength, CouponProbs);
  67.  
  68.     printf("\nCoupon Probabilities:\nSeg Len     Pr%15s", "");
  69.     printf("Cell Expectation     # Variates Required\n");
  70.  
  71.     TotalProb = 0;
  72.     LeftLbl = ">= ";
  73.     for (k = MaxLength - SetSize + 1; k >= 1; --k)
  74.     {
  75.         double  DevReqd = ceil(0.5 + CellExpect/CouponProbs[k-1]);
  76.         printf("%3s%3d  %.11e%10s",
  77.         LeftLbl, k+SetSize-1, CouponProbs[k-1], "");
  78.         printf("%5d%15s%5.f\n", CellExpect, "", DevReqd+k+SetSize-1);
  79.         TotalProb += CouponProbs[k-1];
  80.         LeftLbl = "";
  81.     }
  82.  
  83.     printf("%26.11e  (Total)\n", TotalProb);
  84.     }
  85. }
  86.